home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / x2ftp / msdos / libs / vesatp11 / example / bgidemo2.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1994-05-08  |  35.5 KB  |  1,316 lines

  1. {$X+}
  2.  
  3. { Turbo Graphics }
  4. { Copyright (c) 1985, 1990 by Borland International, Inc. }
  5.  
  6. program BGIDemo;
  7. (*
  8.   Turbo Pascal 6.0 Borland Graphics Interface (BGI) demonstration
  9.   program. This program shows how to use many features of
  10.   the Graph unit.
  11.  
  12.   NOTE: to have this demo use the IBM8514 driver, specify a
  13.   conditional define constant "Use8514" (using the {$DEFINE}
  14.   directive or Options\Compiler\Conditional defines) and then
  15.   re-compile.
  16.  
  17. *)
  18.  
  19. uses
  20.   Crt, Dos, VGraph, Vesa;
  21.  
  22.  
  23. const
  24.   { The five fonts available }
  25.   Fonts : array[0..4] of string[13] =
  26.   ('DefaultFont', 'TriplexFont', 'SmallFont', 'SansSerifFont', 'GothicFont');
  27.  
  28.   { The five predefined line styles supported }
  29.   LineStyles : array[0..4] of string[9] =
  30.   ('SolidLn', 'DottedLn', 'CenterLn', 'DashedLn', 'UserBitLn');
  31.  
  32.   { The twelve predefined fill styles supported }
  33.   FillStyles : array[0..11] of string[14] =
  34.   ('EmptyFill', 'SolidFill', 'LineFill', 'LtSlashFill', 'SlashFill',
  35.    'BkSlashFill', 'LtBkSlashFill', 'HatchFill', 'XHatchFill',
  36.    'InterleaveFill', 'WideDotFill', 'CloseDotFill');
  37.  
  38.   { The two text directions available }
  39.   TextDirect : array[0..1] of string[8] = ('HorizDir', 'VertDir');
  40.  
  41.   { The Horizontal text justifications available }
  42.   HorizJust  : array[0..2] of string[10] = ('LeftText', 'CenterText', 'RightText');
  43.  
  44.   { The vertical text justifications available }
  45.   VertJust   : array[0..2] of string[10] = ('BottomText', 'CenterText', 'TopText');
  46.  
  47. var
  48.   MaxX, MaxY  : word;     { The maximum resolution of the screen }
  49.   ErrorCode   : integer;  { Reports any graphics errors }
  50.   MaxColor      : LONGINT;
  51.   OldExitProc : Pointer;  { Saves exit procedure address }
  52.   mode            : WORD;
  53.  
  54. {$F+}
  55. procedure MyExitProc;
  56. begin
  57.   ExitProc := OldExitProc; { Restore exit procedure address }
  58.   CloseVesa;               { Shut down the graphics system }
  59. end; { MyExitProc }
  60. {$F-}
  61.  
  62. procedure Initialize;
  63. { Initialize graphics and report any errors that may occur }
  64. VAR
  65.     pal    : PaletteType;
  66. begin
  67.   { when using Crt and graphics, turn off Crt's memory-mapped writes }
  68.   DirectVideo := False;
  69.   OldExitProc := ExitProc;                { save previous exit proc }
  70.   ExitProc := @MyExitProc;                { insert our exit proc in chain }
  71.   InitVesa(mode);
  72.   NewPal(pal);
  73.   SetRGBPal(0,0,0,0);
  74.   SetRGBPal(255,63,63,63);
  75.   ErrorCode := GraphResult;             { preserve error return }
  76.   if ErrorCode <> grOK then             { error? }
  77.     begin
  78.       Writeln('Graphics error: ', GraphErrorMsg(ErrorCode));
  79.       Halt(1);                          { Some other error: terminate }
  80.      end;
  81.   Randomize;                                { init random number generator }
  82.   MaxColor := GetMaxColor;                  { Get the maximum allowable drawing color }
  83.   MaxX := GetMaxX;                          { Get screen resolution values }
  84.   MaxY := GetMaxY;
  85. end; { Initialize }
  86.  
  87. function Int2Str(L : LongInt) : string;
  88. { Converts an integer to a string for use with OutText, OutTextXY }
  89. var
  90.   S : string;
  91. begin
  92.   Str(L, S);
  93.   Int2Str := S;
  94. end; { Int2Str }
  95.  
  96. function RandColor : LONGINT;
  97. CONST
  98.     Border = 0;
  99. { Returns a Random non-zero color value that is within the legal
  100.   color range for the selected device driver and graphics mode.
  101.   MaxColor is set to GetMaxColor by Initialize }
  102. begin
  103.     IF MaxColor > $FFFF THEN
  104.         RandColor := RGB(Random($FF-border)+border,Random($FF-border)+border,Random($FF-border)+border)
  105.    ELSE
  106.           RandColor := Random(MaxColor);
  107. end; { RandColor }
  108.  
  109. procedure DefaultColors;
  110. { Select the maximum color in the Palette for the drawing color }
  111. begin
  112.   SetColor(MaxColor);
  113. end; { DefaultColors }
  114.  
  115. procedure DrawBorder;
  116. { Draw a border around the current view port }
  117. var
  118.   ViewPort : ViewPortType;
  119. begin
  120.   DefaultColors;
  121.   SetLineStyle(SolidLn, 0, NormWidth);
  122.   GetViewSettings(ViewPort);
  123.   with ViewPort do
  124.     Rectangle(0, 0, x2-x1, y2-y1);
  125. end; { DrawBorder }
  126.  
  127. procedure FullPort;
  128. { Set the view port to the entire screen }
  129. begin
  130.   SetViewPort(0, 0, MaxX, MaxY, ClipOn);
  131. end; { FullPort }
  132.  
  133. procedure MainWindow(Header : string);
  134. { Make a default window and view port for demos }
  135. begin
  136.   DefaultColors;                           { Reset the colors }
  137.   ClearDevice;                             { Clear the screen }
  138.   SetTextStyle(DefaultFont, HorizDir, 1);  { Default text font }
  139.   SetTextJustify(CenterText, TopText);     { Left justify text }
  140.   FullPort;                                { Full screen view port }
  141.   OutTextXY(MaxX div 2, 2, Header);        { Draw the header }
  142.   { Draw main window }
  143.   SetViewPort(0, TextHeight('M')+4, MaxX, MaxY-(TextHeight('M')+4), ClipOn);
  144.   DrawBorder;                              { Put a border around it }
  145.   { Move the edges in 1 pixel on all sides so border isn't in the view port }
  146.   SetViewPort(1, TextHeight('M')+5, MaxX-1, MaxY-(TextHeight('M')+5), ClipOn);
  147. end; { MainWindow }
  148.  
  149. procedure StatusLine(Msg : string);
  150. { Display a status line at the bottom of the screen }
  151. begin
  152.   FullPort;
  153.   DefaultColors;
  154.   SetTextStyle(DefaultFont, HorizDir, 1);
  155.   SetTextJustify(CenterText, TopText);
  156.   SetLineStyle(SolidLn, 0, NormWidth);
  157.   SetFillStyle(EmptyFill, 0);
  158.   Bar(0, MaxY-(TextHeight('M')+4), MaxX, MaxY);      { Erase old status line }
  159.   Rectangle(0, MaxY-(TextHeight('M')+4), MaxX, MaxY);
  160.   OutTextXY(MaxX div 2, MaxY-(TextHeight('M')+2), Msg);
  161.   { Go back to the main window }
  162.   SetViewPort(1, TextHeight('M')+5, MaxX-1, MaxY-(TextHeight('M')+5), ClipOn);
  163. end; { StatusLine }
  164.  
  165. procedure WaitToGo;
  166. { Wait for the user to abort the program or continue }
  167. const
  168.   Esc = #27;
  169. var
  170.   Ch : char;
  171. begin
  172.   StatusLine('Esc aborts or press a key...');
  173.   repeat until KeyPressed;
  174.   Ch := ReadKey;
  175.   if ch = #0 then ch := readkey;      { trap function keys }
  176.   if Ch = Esc then
  177.     Halt(0)                           { terminate program }
  178.   else
  179.     ClearDevice;                      { clear screen, go on with demo }
  180. end; { WaitToGo }
  181.  
  182. procedure GetDriverAndMode(var DriveStr, ModeStr : string);
  183. { Return strings describing the current device driver and graphics mode
  184.   for display of status report }
  185. begin
  186.   DriveStr := GetDriverName;
  187.   ModeStr := GetModeName(GetGraphMode);
  188. end; { GetDriverAndMode }
  189.  
  190. procedure ReportStatus;
  191. { Display the status of all query functions after InitGraph }
  192. const
  193.   X = 10;
  194. var
  195.   ViewInfo   : ViewPortType;     { Parameters for inquiry procedures }
  196.   LineInfo   : LineSettingsType;
  197.   FillInfo   : FillSettingsType;
  198.   TextInfo   : TextSettingsType;
  199.   Palette    : PaletteType;
  200.   DriverStr  : string;           { Driver and mode strings }
  201.   ModeStr    : string;
  202.   Y          : word;
  203.  
  204. procedure WriteOut(S : string);
  205. { Write out a string and increment to next line }
  206. begin
  207.   OutTextXY(X, Y, S);
  208.   Inc(Y, TextHeight('M')+2);
  209. end; { WriteOut }
  210.  
  211. begin { ReportStatus }
  212.   GetDriverAndMode(DriverStr, ModeStr);   { Get current settings }
  213.   GetViewSettings(ViewInfo);
  214.   GetLineSettings(LineInfo);
  215.   GetFillSettings(FillInfo);
  216.   GetTextSettings(TextInfo);
  217.  
  218.   Y := 4;
  219.   MainWindow('Status report after InitGraph');
  220.   SetTextJustify(LeftText, TopText);
  221.   WriteOut('Graphics device    : '+DriverStr);
  222.   WriteOut('Graphics mode      : '+ModeStr);
  223.   WriteOut('Screen resolution  : (0, 0, '+Int2Str(GetMaxX)+', '+Int2Str(GetMaxY)+')');
  224.   with ViewInfo do
  225.   begin
  226.     WriteOut('Current view port  : ('+Int2Str(x1)+', '+Int2Str(y1)+', '+Int2Str(x2)+', '+Int2Str(y2)+')');
  227.     if ClipOn then
  228.       WriteOut('Clipping           : ON')
  229.     else
  230.       WriteOut('Clipping           : OFF');
  231.   end;
  232.   WriteOut('Current position   : ('+Int2Str(GetX)+', '+Int2Str(GetY)+')');
  233.   WriteOut('GetMaxColor        : '+Int2Str(GetMaxColor));
  234.   WriteOut('Current color      : '+Int2Str(GetColor));
  235.   with LineInfo do
  236.   begin
  237.     WriteOut('Line style         : '+LineStyles[LineStyle]);
  238.     WriteOut('Line thickness     : '+Int2Str(Thickness));
  239.   end;
  240.   with FillInfo do
  241.   begin
  242.     WriteOut('Current fill style : '+FillStyles[Pattern]);
  243.     WriteOut('Current fill color : '+Int2Str(Color));
  244.   end;
  245.   with TextInfo do
  246.   begin
  247.     WriteOut('Current font       : '+Fonts[Font]);
  248.     WriteOut('Text direction     : '+TextDirect[Direction]);
  249.     WriteOut('Character size     : '+Int2Str(CharSize));
  250.     WriteOut('Horizontal justify : '+HorizJust[Horiz]);
  251.     WriteOut('Vertical justify   : '+VertJust[Vert]);
  252.   end;
  253.   WaitToGo;
  254. end; { ReportStatus }
  255.  
  256. procedure FillEllipsePlay;
  257. { Random filled ellipse demonstration }
  258. const
  259.   MaxFillStyles = 12; { patterns 0..11 }
  260. var
  261.   MaxRadius : word;
  262.   FillColor : LONGINT;
  263. begin
  264.   MainWindow('FillEllipse demonstration');
  265.   StatusLine('Esc aborts or press a key');
  266.   MaxRadius := MaxY div 10;
  267.   SetLineStyle(SolidLn, 0, NormWidth);
  268.   repeat
  269.     FillColor := RandColor;
  270.     SetColor(FillColor);
  271.     SetFillStyle(Random(MaxFillStyles), FillColor);
  272.     FillEllipse(Random(MaxX), Random(MaxY),
  273.                 Random(MaxRadius), Random(MaxRadius));
  274.   until KeyPressed;
  275.   WaitToGo;
  276. end; { FillEllipsePlay }
  277.  
  278. procedure SectorPlay;
  279. { Draw random sectors on the screen }
  280. const
  281.   MaxFillStyles = 12; { patterns 0..11 }
  282. var
  283.   MaxRadius : word;
  284.   FillColor : LONGINT;
  285.   EndAngle  : integer;
  286. begin
  287.   MainWindow('Sector demonstration');
  288.   StatusLine('Esc aborts or press a key');
  289.   MaxRadius := MaxY div 10;
  290.   SetLineStyle(SolidLn, 0, NormWidth);
  291.   repeat
  292.     FillColor := RandColor;
  293.     SetColor(FillColor);
  294.     SetFillStyle(Random(MaxFillStyles), FillColor);
  295.     EndAngle := Random(360);
  296.     Sector(Random(MaxX), Random(MaxY), Random(EndAngle), EndAngle,
  297.            Random(MaxRadius), Random(MaxRadius));
  298.   until KeyPressed;
  299.   WaitToGo;
  300. end; { SectorPlay }
  301.  
  302. procedure WriteModePlay;
  303. { Demonstrate the SetWriteMode procedure for XOR lines }
  304. const
  305.   DelayValue = 50;  { milliseconds to delay }
  306. var
  307.   ViewInfo      : ViewPortType;
  308.   Color         : LONGINT;
  309.   Left, Top     : integer;
  310.   Right, Bottom : integer;
  311.   Step          : integer; { step for rectangle shrinking }
  312. begin
  313.   MainWindow('SetWriteMode demonstration');
  314.   StatusLine('Esc aborts or press a key');
  315.   GetViewSettings(ViewInfo);
  316.   Left := 0;
  317.   Top := 0;
  318.   with ViewInfo do
  319.   begin
  320.     Right := x2-x1;
  321.     Bottom := y2-y1;
  322.   end;
  323.   Step := Bottom div 50;
  324.   SetColor(GetMaxColor);
  325.   Line(Left, Top, Right, Bottom);
  326.   Line(Left, Bottom, Right, Top);
  327.   SetWriteMode(XORPut);                    { Set XOR write mode }
  328.   repeat
  329.     Line(Left, Top, Right, Bottom);        { Draw XOR lines }
  330.     Line(Left, Bottom, Right, Top);
  331.     Rectangle(Left, Top, Right, Bottom);   { Draw XOR rectangle }
  332.     Delay(DelayValue);                     { Wait }
  333.     Line(Left, Top, Right, Bottom);        { Erase lines }
  334.     Line(Left, Bottom, Right, Top);
  335.     Rectangle(Left, Top, Right, Bottom);   { Erase rectangle }
  336.     if (Left+Step < Right) and (Top+Step < Bottom) then
  337.       begin
  338.         Inc(Left, Step);                  { Shrink rectangle }
  339.         Inc(Top, Step);
  340.         Dec(Right, Step);
  341.         Dec(Bottom, Step);
  342.       end
  343.     else
  344.       begin
  345.         Color := RandColor;
  346.         SetColor(Color);
  347.         Left := 0;                         { Original large rectangle }
  348.         Top := 0;
  349.         with ViewInfo do
  350.         begin
  351.           Right := x2-x1;
  352.           Bottom := y2-y1;
  353.         end;
  354.       end;
  355.   until KeyPressed;
  356.   SetWriteMode(CopyPut);                   { back to overwrite mode }
  357.   WaitToGo;
  358. end; { WriteModePlay }
  359.  
  360. procedure TextPlay;
  361. { Demonstrate text justifications and text sizing }
  362. var
  363.   Size : word;
  364.   W, H, X, Y : word;
  365.   ViewInfo : ViewPortType;
  366. begin
  367.   MainWindow('SetTextJustify / SetUserCharSize demo');
  368.   GetViewSettings(ViewInfo);
  369.   with ViewInfo do
  370.   begin
  371.     SetTextStyle(TriplexFont, VertDir, 4);
  372.     Y := (y2-y1) - 2;
  373.     SetTextJustify(CenterText, BottomText);
  374.     OutTextXY(2*TextWidth('M'), Y, 'Vertical');
  375.     SetTextStyle(TriplexFont, HorizDir, 4);
  376.     SetTextJustify(LeftText, TopText);
  377.     OutTextXY(2*TextWidth('M'), 2, 'Horizontal');
  378.     SetTextJustify(CenterText, CenterText);
  379.     X := (x2-x1) div 2;
  380.     Y := TextHeight('H');
  381.     for Size := 1 to 4 do
  382.     begin
  383.       SetTextStyle(TriplexFont, HorizDir, Size);
  384.       H := TextHeight('M');
  385.       W := TextWidth('M');
  386.       Inc(Y, H);
  387.       OutTextXY(X, Y, 'Size '+Int2Str(Size));
  388.     end;
  389.     Inc(Y, H div 2);
  390.     SetTextJustify(CenterText, TopText);
  391.      SetUserCharSize(5, 6, 3, 2);
  392.      SetTextStyle(TriplexFont, HorizDir, UserCharSize);
  393.     OutTextXY((x2-x1) div 2, Y, 'User defined size!');
  394.   end;
  395.   WaitToGo;
  396. end; { TextPlay }
  397.  
  398. procedure TextDump;
  399. { Dump the complete character sets to the screen }
  400. const
  401.   CGASizes  : array[0..4] of word = (1, 3, 7, 3, 3);
  402.   NormSizes : array[0..4] of word = (1, 4, 7, 4, 4);
  403. var
  404.   Font : word;
  405.   ViewInfo : ViewPortType;
  406.   Ch : char;
  407. begin
  408.   for Font := 0 to 4 do
  409.   begin
  410.     MainWindow(Fonts[Font]+' character set');
  411.     GetViewSettings(ViewInfo);
  412.     with ViewInfo do
  413.     begin
  414.       SetTextJustify(LeftText, TopText);
  415.       MoveTo(2, 3);
  416.       if Font = DefaultFont then
  417.         begin
  418.           SetTextStyle(Font, HorizDir, 1);
  419.           Ch := #0;
  420.           repeat
  421.                 OutText(Ch);
  422.                 if (GetX + TextWidth('M')) > (x2-x1) then
  423.               MoveTo(2, GetY + TextHeight('M')+3);
  424.             Ch := Succ(Ch);
  425.           until (Ch >= #255);
  426.         end
  427.       else
  428.         begin
  429.           if MaxY < 200 then
  430.             SetTextStyle(Font, HorizDir, CGASizes[Font])
  431.           else
  432.             SetTextStyle(Font, HorizDir, NormSizes[Font]);
  433.           Ch := '!';
  434.           repeat
  435.             OutText(Ch);
  436.             if (GetX + TextWidth('M')) > (x2-x1) then
  437.               MoveTo(2, GetY + TextHeight('M')+3);
  438.             Ch := Succ(Ch);
  439.           until (Ch >= #255);
  440.         end;
  441.     end; { with }
  442.     WaitToGo;
  443.   end; { for loop }
  444. end; { TextDump }
  445.  
  446. procedure LineToPlay;
  447. { Demonstrate MoveTo and LineTo commands }
  448. const
  449.   MaxPoints = 15;
  450. var
  451.   Points     : array[0..MaxPoints] of PointType;
  452.   ViewInfo   : ViewPortType;
  453.   I, J       : integer;
  454.   CenterX    : integer;   { The center point of the circle }
  455.   CenterY    : integer;
  456.   Radius     : word;
  457.   StepAngle  : word;
  458.   Xasp, Yasp : word;
  459.   Radians    : real;
  460.  
  461. function AdjAsp(Value : integer) : integer;
  462. { Adjust a value for the aspect ratio of the device }
  463. begin
  464.   AdjAsp := (LongInt(Value) * Xasp) div Yasp;
  465. end; { AdjAsp }
  466.  
  467. begin
  468.   MainWindow('MoveTo, LineTo demonstration');
  469.   GetAspectRatio(Xasp, Yasp);
  470.   GetViewSettings(ViewInfo);
  471.   with ViewInfo do
  472.   begin
  473.     CenterX := (x2-x1) div 2;
  474.     CenterY := (y2-y1) div 2;
  475.     Radius := CenterY;
  476.     while (CenterY+AdjAsp(Radius)) < (y2-y1)-20 do
  477.       Inc(Radius);
  478.   end;
  479.   StepAngle := 360 div MaxPoints;
  480.   for I := 0 to MaxPoints - 1 do
  481.   begin
  482.     Radians := (StepAngle * I) * Pi / 180;
  483.     Points[I].X := CenterX + round(Cos(Radians) * Radius);
  484.     Points[I].Y := CenterY - AdjAsp(round(Sin(Radians) * Radius));
  485.   end;
  486.   Circle(CenterX, CenterY, Radius);
  487.   for I := 0 to MaxPoints - 1 do
  488.   begin
  489.     for J := I to MaxPoints - 1 do
  490.     begin
  491.       MoveTo(Points[I].X, Points[I].Y);
  492.       LineTo(Points[J].X, Points[J].Y);
  493.     end;
  494.   end;
  495.   WaitToGo;
  496. end; { LineToPlay }
  497.  
  498. procedure LineRelPlay;
  499. { Demonstrate MoveRel and LineRel commands }
  500. const
  501.   MaxPoints = 12;
  502. var
  503.   Poly     : array[1..MaxPoints] of PointType; { Stores a polygon for filling }
  504.   CurrPort : ViewPortType;
  505.  
  506. procedure DrawTesseract;
  507. { Draw a Tesseract on the screen with relative move and
  508.   line drawing commands, also create a polygon for filling }
  509. const
  510.   CheckerBoard : FillPatternType = (0, $10, $28, $44, $28, $10, 0, 0);
  511. var
  512.   X, Y, W, H   : integer;
  513.  
  514. begin
  515.   GetViewSettings(CurrPort);
  516.   with CurrPort do
  517.   begin
  518.     W := (x2-x1) div 9;
  519.     H := (y2-y1) div 8;
  520.     X := ((x2-x1) div 2) - round(2.5 * W);
  521.     Y := ((y2-y1) div 2) - (3 * H);
  522.  
  523.     { Border around viewport is outer part of polygon }
  524.     Poly[1].X := 0;     Poly[1].Y := 0;
  525.     Poly[2].X := x2-x1; Poly[2].Y := 0;
  526.     Poly[3].X := x2-x1; Poly[3].Y := y2-y1;
  527.     Poly[4].X := 0;     Poly[4].Y := y2-y1;
  528.     Poly[5].X := 0;     Poly[5].Y := 0;
  529.     MoveTo(X, Y);
  530.  
  531.     { Grab the whole in the polygon as we draw }
  532.     MoveRel(0, H);      Poly[6].X := GetX;  Poly[6].Y := GetY;
  533.     MoveRel(W, -H);     Poly[7].X := GetX;  Poly[7].Y := GetY;
  534.     MoveRel(4*W, 0);    Poly[8].X := GetX;  Poly[8].Y := GetY;
  535.     MoveRel(0, 5*H);    Poly[9].X := GetX;  Poly[9].Y := GetY;
  536.     MoveRel(-W, H);     Poly[10].X := GetX; Poly[10].Y := GetY;
  537.     MoveRel(-4*W, 0);   Poly[11].X := GetX; Poly[11].Y := GetY;
  538.     MoveRel(0, -5*H);   Poly[12].X := GetX; Poly[12].Y := GetY;
  539.  
  540.     { Fill the polygon with a user defined fill pattern }
  541.     SetFillPattern(CheckerBoard, MaxColor);
  542.     FillPoly(12, Poly);
  543.  
  544.     MoveRel(W, -H);
  545.     LineRel(0, 5*H);   LineRel(2*W, 0);    LineRel(0, -3*H);
  546.     LineRel(W, -H);    LineRel(0, 5*H);    MoveRel(0, -5*H);
  547.     LineRel(-2*W, 0);  LineRel(0, 3*H);    LineRel(-W, H);
  548.     MoveRel(W, -H);    LineRel(W, 0);      MoveRel(0, -2*H);
  549.     LineRel(-W, 0);
  550.  
  551.     { Flood fill the center }
  552.     FloodFill((x2-x1) div 2, (y2-y1) div 2, MaxColor);
  553.   end;
  554. end; { DrawTesseract }
  555.  
  556. begin
  557.   MainWindow('LineRel / MoveRel demonstration');
  558.   GetViewSettings(CurrPort);
  559.   with CurrPort do
  560.     { Move the viewport out 1 pixel from each end }
  561.     SetViewPort(x1-1, y1-1, x2+1, y2+1, ClipOn);
  562.   DrawTesseract;
  563.   WaitToGo;
  564. end; { LineRelPlay }
  565.  
  566. procedure PiePlay;
  567. { Demonstrate  PieSlice and GetAspectRatio commands }
  568. var
  569.   ViewInfo   : ViewPortType;
  570.   CenterX    : integer;
  571.   CenterY    : integer;
  572.   Radius     : word;
  573.   Xasp, Yasp : word;
  574.   X, Y       : integer;
  575.  
  576. function AdjAsp(Value : integer) : integer;
  577. { Adjust a value for the aspect ratio of the device }
  578. begin
  579.   AdjAsp := (LongInt(Value) * Xasp) div Yasp;
  580. end; { AdjAsp }
  581.  
  582. procedure GetTextCoords(AngleInDegrees, Radius : word; var X, Y : integer);
  583. { Get the coordinates of text for pie slice labels }
  584. var
  585.   Radians : real;
  586. begin
  587.   Radians := AngleInDegrees * Pi / 180;
  588.   X := round(Cos(Radians) * Radius);
  589.   Y := round(Sin(Radians) * Radius);
  590. end; { GetTextCoords }
  591.  
  592. begin
  593.   MainWindow('PieSlice / GetAspectRatio demonstration');
  594.   GetAspectRatio(Xasp, Yasp);
  595.   GetViewSettings(ViewInfo);
  596.   with ViewInfo do
  597.   begin
  598.     CenterX := (x2-x1) div 2;
  599.     CenterY := ((y2-y1) div 2) + 20;
  600.     Radius := (y2-y1) div 3;
  601.     while AdjAsp(Radius) < round((y2-y1) / 3.6) do
  602.       Inc(Radius);
  603.   end;
  604.   SetTextStyle(TriplexFont, HorizDir, 4);
  605.   SetTextJustify(CenterText, TopText);
  606.   OutTextXY(CenterX, 0, 'This is a pie chart!');
  607.  
  608.   SetTextStyle(TriplexFont, HorizDir, 3);
  609.  
  610.   SetFillStyle(SolidFill, RandColor);
  611.   PieSlice(CenterX+10, CenterY-AdjAsp(10), 0, 90, Radius);
  612.   GetTextCoords(45, Radius, X, Y);
  613.   SetTextJustify(LeftText, BottomText);
  614.   OutTextXY(CenterX+10+X+TextWidth('H'), CenterY-AdjAsp(10+Y), '25 %');
  615.  
  616.   SetFillStyle(HatchFill, RandColor);
  617.   PieSlice(CenterX, CenterY, 225, 360, Radius);
  618.   GetTextCoords(293, Radius, X, Y);
  619.   SetTextJustify(LeftText, TopText);
  620.   OutTextXY(CenterX+X+TextWidth('H'), CenterY-AdjAsp(Y), '37.5 %');
  621.  
  622.   SetFillStyle(InterleaveFill, RandColor);
  623.   PieSlice(CenterX-10, CenterY, 135, 225, Radius);
  624.   GetTextCoords(180, Radius, X, Y);
  625.   SetTextJustify(RightText, CenterText);
  626.   OutTextXY(CenterX-10+X-TextWidth('H'), CenterY-AdjAsp(Y), '25 %');
  627.  
  628.   SetFillStyle(WideDotFill, RandColor);
  629.   PieSlice(CenterX, CenterY, 90, 135, Radius);
  630.   GetTextCoords(112, Radius, X, Y);
  631.   SetTextJustify(RightText, BottomText);
  632.   OutTextXY(CenterX+X-TextWidth('H'), CenterY-AdjAsp(Y), '12.5 %');
  633.  
  634.   WaitToGo;
  635. end; { PiePlay }
  636.  
  637. procedure Bar3DPlay;
  638. { Demonstrate Bar3D command }
  639. const
  640.   NumBars   = 7;  { The number of bars drawn }
  641.   BarHeight : array[1..NumBars] of byte = (1, 3, 2, 5, 4, 2, 1);
  642.   YTicks    = 5;  { The number of tick marks on the Y axis }
  643. var
  644.   ViewInfo : ViewPortType;
  645.   H        : word;
  646.   XStep    : real;
  647.   YStep    : real;
  648.   I, J     : integer;
  649.   Depth    : word;
  650.   Color    : LONGINT;
  651. begin
  652.   MainWindow('Bar3D / Rectangle demonstration');
  653.   H := 3*TextHeight('M');
  654.   GetViewSettings(ViewInfo);
  655.   SetTextJustify(CenterText, TopText);
  656.   SetTextStyle(TriplexFont, HorizDir, 4);
  657.   OutTextXY(MaxX div 2, 6, 'These are 3D bars !');
  658.   SetTextStyle(DefaultFont, HorizDir, 1);
  659.   with ViewInfo do
  660.     SetViewPort(x1+50, y1+40, x2-50, y2-10, ClipOn);
  661.   GetViewSettings(ViewInfo);
  662.   with ViewInfo do
  663.   begin
  664.     Line(H, H, H, (y2-y1)-H);
  665.     Line(H, (y2-y1)-H, (x2-x1)-H, (y2-y1)-H);
  666.     YStep := ((y2-y1)-(2*H)) / YTicks;
  667.     XStep := ((x2-x1)-(2*H)) / NumBars;
  668.     J := (y2-y1)-H;
  669.     SetTextJustify(CenterText, CenterText);
  670.  
  671.     { Draw the Y axis and ticks marks }
  672.     for I := 0 to Yticks do
  673.     begin
  674.       Line(H div 2, J, H, J);
  675.       OutTextXY(0, J, Int2Str(I));
  676.       J := Round(J-Ystep);
  677.     end;
  678.  
  679.  
  680.     Depth := trunc(0.25 * XStep);    { Calculate depth of bar }
  681.  
  682.     { Draw X axis, bars, and tick marks }
  683.     SetTextJustify(CenterText, TopText);
  684.     J := H;
  685.     for I := 1 to Succ(NumBars) do
  686.     begin
  687.       SetColor(MaxColor);
  688.       Line(J, (y2-y1)-H, J, (y2-y1-3)-(H div 2));
  689.       OutTextXY(J, (y2-y1)-(H div 2), Int2Str(I-1));
  690.       if I <> Succ(NumBars) then
  691.       begin
  692.         Color := RandColor;
  693.         SetFillStyle(I, Color);
  694.         SetColor(Color);
  695.         Bar3D(J, round((y2-y1-H)-(BarHeight[I] * Ystep)),
  696.                  round(J+Xstep-Depth), round((y2-y1)-H-1), Depth, TopOn);
  697.         J := Round(J+Xstep);
  698.       end;
  699.     end;
  700.  
  701.   end;
  702.   WaitToGo;
  703. end; { Bar3DPlay }
  704.  
  705. procedure BarPlay;
  706. { Demonstrate Bar command }
  707. const
  708.   NumBars   = 5;
  709.   BarHeight : array[1..NumBars] of byte = (1, 3, 5, 2, 4);
  710.   Styles    : array[1..NumBars] of byte = (1, 3, 10, 5, 9);
  711. var
  712.   ViewInfo  : ViewPortType;
  713.   BarNum    : word;
  714.   H         : word;
  715.   XStep     : real;
  716.   YStep     : real;
  717.   I, J      : integer;
  718.   Color     : LONGINT;
  719. begin
  720.   MainWindow('Bar / Rectangle demonstration');
  721.   H := 3*TextHeight('M');
  722.   GetViewSettings(ViewInfo);
  723.   SetTextJustify(CenterText, TopText);
  724.   SetTextStyle(TriplexFont, HorizDir, 4);
  725.   OutTextXY(MaxX div 2, 6, 'These are 2D bars !');
  726.   SetTextStyle(DefaultFont, HorizDir, 1);
  727.   with ViewInfo do
  728.     SetViewPort(x1+50, y1+30, x2-50, y2-10, ClipOn);
  729.   GetViewSettings(ViewInfo);
  730.   with ViewInfo do
  731.   begin
  732.     Line(H, H, H, (y2-y1)-H);
  733.     Line(H, (y2-y1)-H, (x2-x1)-H, (y2-y1)-H);
  734.     YStep := ((y2-y1)-(2*H)) / NumBars;
  735.     XStep := ((x2-x1)-(2*H)) / NumBars;
  736.     J := (y2-y1)-H;
  737.     SetTextJustify(CenterText, CenterText);
  738.  
  739.     { Draw Y axis with tick marks }
  740.     for I := 0 to NumBars do
  741.     begin
  742.       Line(H div 2, J, H, J);
  743.       OutTextXY(0, J, Int2Str(i));
  744.       J := Round(J-Ystep);
  745.     end;
  746.  
  747.     { Draw X axis, bars, and tick marks }
  748.     J := H;
  749.     SetTextJustify(CenterText, TopText);
  750.     for I := 1 to Succ(NumBars) do
  751.     begin
  752.       SetColor(MaxColor);
  753.       Line(J, (y2-y1)-H, J, (y2-y1-3)-(H div 2));
  754.       OutTextXY(J, (y2-y1)-(H div 2), Int2Str(I));
  755.       if I <> Succ(NumBars) then
  756.       begin
  757.         Color := RandColor;
  758.         SetFillStyle(Styles[I], Color);
  759.         SetColor(Color);
  760.         Bar(J, round((y2-y1-H)-(BarHeight[I] * Ystep)), round(J+Xstep), (y2-y1)-H-1);
  761.         Rectangle(J, round((y2-y1-H)-(BarHeight[I] * Ystep)), round(J+Xstep), (y2-y1)-H-1);
  762.       end;
  763.       J := Round(J+Xstep);
  764.     end;
  765.  
  766.   end;
  767.   WaitToGo;
  768. end; { BarPlay }
  769.  
  770. procedure CirclePlay;
  771. { Draw random circles on the screen }
  772. var
  773.   MaxRadius : word;
  774. begin
  775.   MainWindow('Circle demonstration');
  776.   StatusLine('Esc aborts or press a key');
  777.   MaxRadius := MaxY div 10;
  778.   SetLineStyle(SolidLn, 0, NormWidth);
  779.   repeat
  780.     SetColor(RandColor);
  781.     Circle(Random(MaxX), Random(MaxY), Random(MaxRadius));
  782.   until KeyPressed;
  783.   WaitToGo;
  784. end; { CirclePlay }
  785.  
  786.  
  787. procedure RandBarPlay;
  788. { Draw random bars on the screen }
  789. var
  790.   MaxWidth  : integer;
  791.   MaxHeight : integer;
  792.   ViewInfo  : ViewPortType;
  793.   Color     : LONGINT;
  794. begin
  795.   MainWindow('Random Bars');
  796.   StatusLine('Esc aborts or press a key');
  797.   GetViewSettings(ViewInfo);
  798.   with ViewInfo do
  799.   begin
  800.     MaxWidth := x2-x1;
  801.     MaxHeight := y2-y1;
  802.   end;
  803.   repeat
  804.     Color := RandColor;
  805.     SetColor(Color);
  806.     SetFillStyle(Random(CloseDotFill)+1, Color);
  807.     Bar3D(Random(MaxWidth), Random(MaxHeight),
  808.           Random(MaxWidth), Random(MaxHeight), 0, TopOff);
  809.   until KeyPressed;
  810.   WaitToGo;
  811. end; { RandBarPlay }
  812.  
  813. procedure ArcPlay;
  814. { Draw random arcs on the screen }
  815. var
  816.   MaxRadius : word;
  817.   EndAngle : word;
  818.   ArcInfo : ArcCoordsType;
  819. begin
  820.   MainWindow('Arc / GetArcCoords demonstration');
  821.   StatusLine('Esc aborts or press a key');
  822.   MaxRadius := MaxY div 10;
  823.   repeat
  824.     SetColor(RandColor);
  825.     EndAngle := Random(360);
  826.     SetLineStyle(SolidLn, 0, NormWidth);
  827.     Arc(Random(MaxX), Random(MaxY), Random(EndAngle), EndAngle, Random(MaxRadius));
  828.     GetArcCoords(ArcInfo);
  829.     with ArcInfo do
  830.     begin
  831.       Line(X, Y, XStart, YStart);
  832.       Line(X, Y, Xend, Yend);
  833.     end;
  834.   until KeyPressed;
  835.   WaitToGo;
  836. end; { ArcPlay }
  837.  
  838. procedure PutPixelPlay;
  839. { Demonstrate the PutPixel and GetPixel commands }
  840. const
  841.   Seed   = 1962; { A seed for the random number generator }
  842.   NumPts = 2000; { The number of pixels plotted }
  843.   Esc    = #27;
  844. var
  845.   I : word;
  846.   X, Y         : word;
  847.   color        : LONGINT;
  848.   XMax, YMax  : integer;
  849.   ViewInfo    : ViewPortType;
  850. begin
  851.   MainWindow('PutPixel / GetPixel demonstration');
  852.   StatusLine('Esc aborts or press a key...');
  853.  
  854.   GetViewSettings(ViewInfo);
  855.   with ViewInfo do
  856.   begin
  857.     XMax := (x2-x1-1);
  858.     YMax := (y2-y1-1);
  859.   end;
  860.  
  861.   while not KeyPressed do
  862.   begin
  863.     { Plot random pixels }
  864.     RandSeed := Seed;
  865.     I := 0;
  866.     while (not KeyPressed) and (I < NumPts) do
  867.     begin
  868.       Inc(I);
  869.         PutPixel(Random(XMax)+1, Random(YMax)+1, RandColor);
  870.     end;
  871.  
  872.     { Erase pixels }
  873.     RandSeed := Seed;
  874.     I := 0;
  875.     while (not KeyPressed) and (I < NumPts) do
  876.     begin
  877.       Inc(I);
  878.       X := Random(XMax)+1;
  879.       Y := Random(YMax)+1;
  880.       Color := GetPixel(X, Y);
  881.         if Color = RandColor then
  882.           PutPixel(X, Y, 0);
  883.      end;
  884.   end;
  885.   WaitToGo;
  886. end; { PutPixelPlay }
  887.  
  888. procedure PutImagePlay;
  889. { Demonstrate the GetImage and PutImage commands }
  890.  
  891. const
  892.   r  = 20;
  893.   StartX = 100;
  894.   StartY = 50;
  895.  
  896. var
  897.   CurPort : ViewPortType;
  898.  
  899. procedure MoveSaucer(var X, Y : integer; Width, Height : integer);
  900. var
  901.   Step : integer;
  902. begin
  903.   Step := Random(2*r);
  904.   if Odd(Step) then
  905.     Step := -Step;
  906.   X := X + Step;
  907.   Step := Random(r);
  908.   if Odd(Step) then
  909.     Step := -Step;
  910.   Y := Y + Step;
  911.  
  912.   { Make saucer bounce off viewport walls }
  913.   with CurPort do
  914.   begin
  915.     if (x1 + X + Width - 1 > x2) then
  916.       X := x2-x1 - Width + 1
  917.     else
  918.       if (X < 0) then
  919.         X := 0;
  920.     if (y1 + Y + Height - 1 > y2) then
  921.       Y := y2-y1 - Height + 1
  922.     else
  923.       if (Y < 0) then
  924.         Y := 0;
  925.   end;
  926. end; { MoveSaucer }
  927.  
  928. var
  929.   Pausetime : word;
  930.   Saucer    : pointer;
  931.   X, Y      : integer;
  932.   ulx, uly  : word;
  933.   lrx, lry  : word;
  934.   Size      : word;
  935.   I         : word;
  936. begin
  937.   ClearDevice;
  938.   FullPort;
  939.  
  940.   { PaintScreen }
  941.   ClearDevice;
  942.   MainWindow('GetImage / PutImage Demonstration');
  943.   StatusLine('Esc aborts or press a key...');
  944.   GetViewSettings(CurPort);
  945.  
  946.   { DrawSaucer }
  947.   Ellipse(StartX, StartY, 0, 360, r, (r div 3)+2);
  948.   Ellipse(StartX, StartY-4, 190, 357, r, r div 3);
  949.   Line(StartX+7, StartY-6, StartX+10, StartY-12);
  950.   Circle(StartX+10, StartY-12, 2);
  951.   Line(StartX-7, StartY-6, StartX-10, StartY-12);
  952.   Circle(StartX-10, StartY-12, 2);
  953.   SetFillStyle(SolidFill, MaxColor);
  954.   FloodFill(StartX+1, StartY+4, GetColor);
  955.  
  956.   { ReadSaucerImage }
  957.   ulx := StartX-(r+1);
  958.   uly := StartY-14;
  959.   lrx := StartX+(r+1);
  960.   lry := StartY+(r div 3)+3;
  961.  
  962.   Size := ImageSize(ulx, uly, lrx, lry);
  963.   GetMem(Saucer, Size);
  964.   GetImage(ulx, uly, lrx, lry, Saucer^);
  965.   SetWriteMode(XorPut);
  966.   PutImage(ulx,uly,lrx,lry,Saucer^);
  967.  
  968.   { Plot some "stars" }
  969.   for I := 1 to 1000 do
  970.      PutPixel(Random(MaxX), Random(MaxY), RandColor);
  971.   X := MaxX div 2;
  972.   Y := MaxY div 2;
  973.   PauseTime := 70;
  974.  
  975.   { Move the saucer around }
  976.   repeat
  977.      PutImage(x+ulx,y+uly,x+lrx,y+lry,Saucer^);
  978.      Delay(PauseTime);
  979.      PutImage(x+ulx,y+uly,x+lrx,y+lry,Saucer^);
  980.      MoveSaucer(X, Y, lrx - ulx + 1, lry - uly + 1);  { width/height }
  981.   until KeyPressed;
  982.   FreeMem(Saucer, size);
  983.   WaitToGo;
  984.   SetWriteMode(CopyPut);
  985. end; { PutImagePlay }
  986.  
  987. procedure PolyPlay;
  988. { Draw random polygons with random fill styles on the screen }
  989. const
  990.   MaxPts = 5;
  991. type
  992.   PolygonType = array[1..MaxPts] of PointType;
  993. var
  994.   Poly : PolygonType;
  995.   I : word;
  996.   color    : LONGINT;
  997. begin
  998.   MainWindow('FillPoly demonstration');
  999.   StatusLine('Esc aborts or press a key...');
  1000.   repeat
  1001.     Color := RandColor;
  1002.     SetFillStyle(Random(11)+1, Color);
  1003.     SetColor(Color);
  1004.     for I := 1 to MaxPts do
  1005.       with Poly[I] do
  1006.       begin
  1007.         X := Random(MaxX);
  1008.         Y := Random(MaxY);
  1009.       end;
  1010.     FillPoly(MaxPts, Poly);
  1011.   until KeyPressed;
  1012.   WaitToGo;
  1013. end; { PolyPlay }
  1014.  
  1015. procedure FillStylePlay;
  1016. { Display all of the predefined fill styles available }
  1017. var
  1018.   Style    : word;
  1019.   Width    : word;
  1020.   Height   : word;
  1021.   X, Y     : word;
  1022.   I, J     : word;
  1023.   ViewInfo : ViewPortType;
  1024.  
  1025. procedure DrawBox(X, Y : word);
  1026. begin
  1027.   SetFillStyle(Style, MaxColor);
  1028.   with ViewInfo do
  1029.     Bar(X, Y, X+Width, Y+Height);
  1030.   Rectangle(X, Y, X+Width, Y+Height);
  1031.   OutTextXY(X+(Width div 2), Y+Height+4, Int2Str(Style));
  1032.   Inc(Style);
  1033. end; { DrawBox }
  1034.  
  1035. begin
  1036.   MainWindow('Pre-defined fill styles');
  1037.   GetViewSettings(ViewInfo);
  1038.   with ViewInfo do
  1039.   begin
  1040.     Width := 2 * ((x2+1) div 13);
  1041.     Height := 2 * ((y2-10) div 10);
  1042.   end;
  1043.   X := Width div 2;
  1044.   Y := Height div 2;
  1045.   Style := 0;
  1046.   for J := 1 to 3 do
  1047.   begin
  1048.     for I := 1 to 4 do
  1049.     begin
  1050.       DrawBox(X, Y);
  1051.       Inc(X, (Width div 2) * 3);
  1052.     end;
  1053.     X := Width div 2;
  1054.     Inc(Y, (Height div 2) * 3);
  1055.   end;
  1056.   SetTextJustify(LeftText, TopText);
  1057.   WaitToGo;
  1058. end; { FillStylePlay }
  1059.  
  1060. procedure FillPatternPlay;
  1061. { Display some user defined fill patterns }
  1062. const
  1063.   Patterns : array[0..11] of FillPatternType = (
  1064.   ($AA, $55, $AA, $55, $AA, $55, $AA, $55),
  1065.   ($33, $33, $CC, $CC, $33, $33, $CC, $CC),
  1066.   ($F0, $F0, $F0, $F0, $F, $F, $F, $F),
  1067.   (0, $10, $28, $44, $28, $10, 0, 0),
  1068.   (0, $70, $20, $27, $25, $27, $4, $4),
  1069.   (0, 0, 0, $18, $18, 0, 0, 0),
  1070.   (0, 0, $3C, $3C, $3C, $3C, 0, 0),
  1071.   (0, $7E, $7E, $7E, $7E, $7E, $7E, 0),
  1072.   (0, 0, $22, $8, 0, $22, $1C, 0),
  1073.   ($FF, $7E, $3C, $18, $18, $3C, $7E, $FF),
  1074.   (0, $10, $10, $7C, $10, $10, 0, 0),
  1075.   (0, $42, $24, $18, $18, $24, $42, 0));
  1076. var
  1077.   Style    : word;
  1078.   Width    : word;
  1079.   Height   : word;
  1080.   X, Y     : word;
  1081.   I, J     : word;
  1082.   ViewInfo : ViewPortType;
  1083.  
  1084. procedure DrawBox(X, Y : word);
  1085. begin
  1086.   SetFillPattern(Patterns[Style], MaxColor);
  1087.   with ViewInfo do
  1088.     Bar(X, Y, X+Width, Y+Height);
  1089.   Rectangle(X, Y, X+Width, Y+Height);
  1090.   Inc(Style);
  1091. end; { DrawBox }
  1092.  
  1093. begin
  1094.   MainWindow('User defined fill styles');
  1095.   GetViewSettings(ViewInfo);
  1096.   with ViewInfo do
  1097.   begin
  1098.     Width := 2 * ((x2+1) div 13);
  1099.     Height := 2 * ((y2-10) div 10);
  1100.   end;
  1101.   X := Width div 2;
  1102.   Y := Height div 2;
  1103.   Style := 0;
  1104.   for J := 1 to 3 do
  1105.   begin
  1106.     for I := 1 to 4 do
  1107.     begin
  1108.       DrawBox(X, Y);
  1109.       Inc(X, (Width div 2) * 3);
  1110.     end;
  1111.     X := Width div 2;
  1112.     Inc(Y, (Height div 2) * 3);
  1113.   end;
  1114.   SetTextJustify(LeftText, TopText);
  1115.   WaitToGo;
  1116. end; { FillPatternPlay }
  1117.  
  1118. procedure PalettePlay;
  1119. { Demonstrate the use of the SetPalette command }
  1120. const
  1121.   XBars = 15;
  1122.   YBars = 10;
  1123. var
  1124.   I, J     : word;
  1125.   X, Y     : word;
  1126.   Color    : LONGINT;
  1127.   ViewInfo : ViewPortType;
  1128.   Width    : word;
  1129.   Height   : word;
  1130.   OldPal   : PaletteType;
  1131. begin
  1132.   GetPal(OldPal);
  1133.   MainWindow('Palette demonstration');
  1134.   StatusLine('Press any key...');
  1135.   GetViewSettings(ViewInfo);
  1136.   with ViewInfo do
  1137.   begin
  1138.     Width := (x2-x1) div XBars;
  1139.     Height := (y2-y1) div YBars;
  1140.   end;
  1141.   X := 0; Y := 0;
  1142.   Color := 0;
  1143.   for J := 1 to YBars do
  1144.   begin
  1145.     for I := 1 to XBars do
  1146.     begin
  1147.       SetFillStyle(SolidFill, Color);
  1148.       Bar(X, Y, X+Width, Y+Height);
  1149.       Inc(X, Width+1);
  1150.       Inc(Color);
  1151.       Color := Color mod (MaxColor+1);
  1152.     end;
  1153.     X := 0;
  1154.     Inc(Y, Height+1);
  1155.   end;
  1156.   repeat
  1157.      SetRGBPal(Random(GetMaxColor + 1),Random(65),Random(65),Random(65));
  1158.   until KeyPressed;
  1159.   SetPal(OldPal);
  1160.   WaitToGo;
  1161. end; { PalettePlay }
  1162.  
  1163. procedure CrtModePlay;
  1164. { Demonstrate the use of RestoreCrtMode and SetGraphMode }
  1165. var
  1166.   ViewInfo : ViewPortType;
  1167.   Ch       : char;
  1168. begin
  1169.   MainWindow('SetGraphMode / RestoreCrtMode demo');
  1170.   GetViewSettings(ViewInfo);
  1171.   SetTextJustify(CenterText, CenterText);
  1172.   with ViewInfo do
  1173.   begin
  1174.     OutTextXY((x2-x1) div 2, (y2-y1) div 2, 'Now you are in graphics mode');
  1175.     StatusLine('Press any key for text mode...');
  1176.     repeat until KeyPressed;
  1177.     Ch := ReadKey;
  1178.     if ch = #0 then ch := readkey;    { trap function keys }
  1179.     RestoreCrtmode;
  1180.     Writeln('Now you are in text mode.');
  1181.     Write('Press any key to go back to graphics...');
  1182.     repeat until KeyPressed;
  1183.     Ch := ReadKey;
  1184.     if ch = #0 then ch := readkey;    { trap function keys }
  1185.     SetGraphMode(GetGraphMode);
  1186.     MainWindow('SetGraphMode / RestoreCrtMode demo');
  1187.     SetTextJustify(CenterText, CenterText);
  1188.     OutTextXY((x2-x1) div 2, (y2-y1) div 2, 'Back in graphics mode...');
  1189.   end;
  1190.   WaitToGo;
  1191. end; { CrtModePlay }
  1192.  
  1193.  
  1194. procedure SayGoodbye;
  1195. { Say goodbye and then exit the program }
  1196. var
  1197.   ViewInfo : ViewPortType;
  1198. begin
  1199.   MainWindow('');
  1200.   GetViewSettings(ViewInfo);
  1201.   SetTextStyle(TriplexFont, HorizDir, 4);
  1202.   SetTextJustify(CenterText, CenterText);
  1203.   with ViewInfo do
  1204.     OutTextXY((x2-x1) div 2, (y2-y1) div 2, 'That''s all folks!');
  1205.   StatusLine('Press any key to quit...');
  1206.   repeat until KeyPressed;
  1207. end; { SayGoodbye }
  1208.  
  1209.  
  1210. PROCEDURE SelectMode;
  1211. VAR
  1212.     choice1,choice2     : CHAR;
  1213.    xsize,ysize            : WORD;
  1214. BEGIN
  1215.     (* Let's select a mode *)
  1216.     ClrScr;
  1217.     WriteLn('VESADEMO:');
  1218.     WriteLn('1. 256 colors');
  1219.     WriteLn('2. 32768 colors');
  1220.     WriteLn('3. 65536 colors');
  1221.     WriteLn('4. 16777216 colors');
  1222.     WriteLn('Q uit');
  1223.     WriteLn;
  1224.     Write('Your choice: ');
  1225.     REPEAT
  1226.         ReadLn(choice1);
  1227.     UNTIL choice1 IN ['1'..'4','q'];
  1228.     IF choice1 = 'q' THEN Halt;
  1229.  
  1230.     WriteLn;
  1231.     WriteLn;
  1232.     WriteLn('a. 320x200');
  1233.     WriteLn('b. 640x480');
  1234.     WriteLn('c. 800x600');
  1235.     WriteLn('d. 1024x768');
  1236.     WriteLn('e. 1280x1024');
  1237.     WriteLn('Q uit');
  1238.     WriteLn;
  1239.     Write('Your choice: ');
  1240.     REPEAT
  1241.         ReadLn(choice2);
  1242.     UNTIL choice2 IN ['a'..'e','q'];
  1243.     IF choice2 = 'q' THEN Halt;
  1244.  
  1245.     CASE choice2 OF
  1246.         'a' : BEGIN
  1247.             xsize := 320;
  1248.             ysize := 200;
  1249.         END;
  1250.         'b' : BEGIN
  1251.             xsize := 640;
  1252.             ysize := 480;
  1253.         END;
  1254.         'c' : BEGIN
  1255.             xsize := 800;
  1256.             ysize := 600;
  1257.         END;
  1258.         'd' : BEGIN
  1259.             xsize := 1024;
  1260.             ysize := 768;
  1261.         END;
  1262.         'e' : BEGIN
  1263.             xsize := 1280;
  1264.             ysize := 1024;
  1265.         END;
  1266.     END;
  1267.     CASE choice1 OF
  1268.         '1' : mode := FindVesaMode(xsize,ysize,8);
  1269.         '2' : mode := FindVesaMode(xsize,ysize,15);
  1270.         '3' : mode := FindVesaMode(xsize,ysize,16);
  1271.         '4' : BEGIN
  1272.             mode := FindVesaMode(xsize,ysize,24);
  1273.             IF mode = 0 THEN
  1274.                 mode := FindVesaMode(xsize,ysize,32);
  1275.         END;
  1276.     END;
  1277.     IF mode = 0 THEN BEGIN
  1278.         WriteLn('No such mode could be found !');
  1279.         WriteLn('Switching to to 320x200x256');
  1280.         ReadKey;
  1281.         mode := V320x200x256;
  1282.     END;
  1283. END;
  1284.  
  1285. begin { program body }
  1286.  
  1287.   SelectMode;
  1288.   Initialize;
  1289.  
  1290.   ReportStatus;
  1291.   FillEllipsePlay;
  1292.   SectorPlay;
  1293.   WriteModePlay;
  1294.  
  1295.   IF MaxColor = 255 THEN
  1296.      PalettePlay;
  1297.   PutPixelPlay;
  1298.   PutImagePlay;
  1299.   RandBarPlay;
  1300.   BarPlay;
  1301.   Bar3DPlay;
  1302.   ArcPlay;
  1303.   CirclePlay;
  1304.   PiePlay;
  1305.   LineToPlay;
  1306.   LineRelPlay;
  1307.   TextDump;
  1308.   TextPlay;
  1309.   CrtModePlay;
  1310.   FillStylePlay;
  1311.   FillPatternPlay;
  1312.   PolyPlay;
  1313.   SayGoodbye;
  1314.   CloseVesa;
  1315. end.
  1316.